#!/bin/sh

# Put information on each key source in a separate array. Each array should
# have exactly four elements: an URL, an extended regular expression for sed's
# "s" command (it has to be recognized by grep as well), a replacement for the
# expression, and key's designation (system, provider, number).

tps1=("http://autoaes.prophp.org/Tofleboss.html"
      ".*([0-9A-F]{16}):([0-9A-F]{16})"
      "\1\2"
      "V 007C00 TPS")

tps2=("http://autoaes.atspace.name/Tofleboss.html"
      ".*([0-9A-F]{16}):([0-9A-F]{16})"
      "\1\2"
      "V 007C00 TPS")

tps3=("http://one.fsphost.com/autoaes/Tofleboss.html"
      ".*([0-9A-F]{16}):([0-9A-F]{16})"
      "\1\2"
      "V 007C00 TPS")

tps4=("http://autoaes.50webs.com/Tofleboss.html"
      ".*([0-9A-F]{16}):([0-9A-F]{16})"
      "\1\2"
      "V 007C00 TPS")

# Once you define keys' sources, you need to fill the following variable with
# names of source arrays you want to enable (separated with spaces).

keys="tps1 tps2 tps3 tps4"

# Below is the actual code that makes use of the information defined above.
# Do not edit the rest of this file unless you really need to and know what
# you are doing! If you need to add code for keys unsupported by this script,
# do it earlier in the file.

for i in $keys; do
	eval "t=(\"\${$i[@]}\")"
	key=`wget -q -T 60 -O- -U Mozilla "--referer=${t[0]}" "${t[0]}" 2> /dev/null | egrep "${t[1]}" | sed -r "s/${t[1]}/${t[2]}/"`
	test -n "$key" && echo "${t[3]} $key"
done
